<template>
    <div class="account-box">
          <div class="isMsgLogin-box">
            <div v-if="isMsgLogin" @click='isMsgLogin=false'><i class="iconfont icon-user"></i>使用账户登陆</div>
            <div v-else @click="isMsgLogin=true"><i class="iconfont icon-msg"></i>使用短信登陆</div>
          </div>
          <!-- Field 添加name属性，作用是指定使用schema中哪个校验规则
          Form 添加 v-slot="{errors}" 使用作用域插槽暴露 errors 错误对象
          通过 errors['校验规则名称'] 取出错误信息，有则显示，无即隐藏 -->
          <Form class="form" :validation-schema="schema" v-slot="{errors}" autocomplete="off" ref="formCom">
            <!-- 验证码登陆 -->
            <template v-if='isMsgLogin'>
              <div class="form-item">
                <div class="input" >
                  <i class="iconfont icon-user"></i>
                  <Field :class="[input1, {error:errors.mobile}]" type="text" v-model="form.mobile" name="mobile" placeholder="请输入手机号" />
                </div>
                 <div class="error" v-if="errors.mobile">
                     <i class="iconfont icon-warning"></i> {{errors.mobile}}
                </div>
              </div>
              <div class="form-item">
                <div class="input">
                  <i class="iconfont icon-code"></i>
                  <Field :class="[input1, {error:errors.code}]" type="text" placeholder="请输入短信码" v-model="form.code" name="code" />
                  <span class="spanBut">发送验证码</span>
                </div>
                 <div class="error"  v-if="errors.code">
                     <i class="iconfont icon-warning"></i> {{errors.code}}
                </div>
              </div>
            </template>
            <!-- 账户登陆  -->
            <template v-else>
              <div class="form-item">
                <div class="input">
                  <i class="iconfont icon-user"></i>
                  <Field :class="[input1, {error:errors.account}]" type="text" v-model="form.account" name="account" placeholder="请输入用户名" />
                </div>
                <!-- 错误提示 -->
                <div class="error" v-if="errors.account">
                     <i class="iconfont icon-warning"></i> {{errors.account}}
                </div>
              </div>
              <div>
                <div class="input">
                  <i class="iconfont icon-lock"></i>
                  <Field :class="[input1, {error:errors.password}]" type="password" v-model="form.password" name="password" placeholder="请输入密码" />
                </div>
                <div class="error" v-if="errors.password">
                     <i class="iconfont icon-warning"></i> {{errors.password}}
                </div>
              </div>
            </template>
            <div class="form-item">
              <div class="argee">
                <Field as="XtxCheckbox" name="isAgree" v-model="form.isAgree" /><span>我已同意</span><a href="javascript:;">《隐私条款》</a><span>和</span><a
                  href="javascript:;">《服务条款》</a>
              </div>
              <div class="error" v-if="errors.isAgree">
              <i class="iconfont icon-warning" />
              {{errors.isAgree}}
              </div>
            </div>
            <div class="form-item">
              <a href="javascript:;" class="btn">登录</a>
            </div>
          </Form>
          <div class="actionQQ">
            <div class="qqImg">
              <img src="https://qzonestyle.gtimg.cn/qzone/vas/opensns/res/img/Connect_logo_7.png" alt="">
            </div>
            <div class="feeac">
              <a href="javascript:;">忘记密码</a>
              <a href="javascript:;">免费注册</a>
            </div>
          </div>
        </div>
        <!-- 扫码登陆 -->
        <!-- <div class="qrcode-box"></div> -->
</template>
<script>
// 安装表单验证npm i vee-validate@4.0.3，导入form和field组件
import { Form, Field } from 'vee-validate'
import { ref, reactive } from 'vue'
// 导入写好的校验规则
import veeSchema from '@/utils/vee-validate-schema'
export default {
  name: 'form',
  components: { Form, Field },
  setup () {
    //   始发短信登陆
    const isMsgLogin = ref(false) // vue3ref 的使用和vue2有很大不同 ref(展示的内容)
    // 监听复杂类型要使用reactive函数
    const form = reactive({
      isAgree: true, // 是否同意校验框
      account: null, // 用户
      password: null, // 密码
      mobile: null, // 电话
      code: null // 验证码
    })
    // 校验
    const myschema = {
      isAgree: veeSchema.isAgree,
      account: veeSchema.account,
      password: veeSchema.password,
      mobile: veeSchema.mobile,
      code: veeSchema.code
    }
    return { isMsgLogin, form, schema: myschema }
  }

}
</script>
<style lang="less">
    .account-box{
         .isMsgLogin-box {
      height: 50px;
      padding: 0 37px;
      line-height: 50px;
      color: #27ba9b;
      text-align: right;
      input {
        height: 35px;
        padding: 5px;
      }
      i {
        margin-right: 5px;
        line-height: 50px;
        font-size: 14px;
      }
    }
    .form {
      padding: 0 37px;
      .input {
        border: 1px solid #cfcdcd;
        display: flex;
        margin-bottom: 30px;
        i {
          width: 35px;
          height: 35px;
          line-height: 35px;
          background-color: #cfcdcd;
          color: #fff;
        }
        input[type="text"], input[type="search"], input[type="password"], input[type="checkbox"] {
          flex: 1;
          padding: 0 10px !important;
        }
        .spanBut {
          display: inline-block;
          height: 35px;
        //   width: 120px;
          line-height: 35px;
          padding: 0 10px;
          font-size: 12px;
          background-color: #f5f5f5;
        }
      }
      .argee {
        a {
          color: #006699 !important;
        }
      }
      .btn {
        background-color: #27ba9b;
        width: 100%;
        height: 35px;
        line-height: 35px;
        color: #fff;
        display: inline-block;
        margin-top: 25px;
      }
    }
    .actionQQ {
      margin-top: 20px;
      display: flex;
      padding: 0 37px;
      .qqImg{
          img{
              width: 100%;
              height: 100%;
          }
      }
      .feeac {
        flex: 1;
        text-align: right;
        a{
            display: inline-block;
            margin-left: 10px;
            font-size: 14px;
            color: #999999;
        }
      }
    }
    }
</style>
